package com.niit.house.lyl.address;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;


public class AddressMapper extends Mapper<Object, Text, Text, Text> {

    @Override
    protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {
        String[] record = value.toString().split(",");
        try {
            String district = record[1]; // 房屋所属市辖区在第1个字段
            String address = record[2]; // 房屋具体地址在第2个字段

            context.write(new Text(address), new Text(district));
        } catch (NumberFormatException | ArrayIndexOutOfBoundsException | NullPointerException e) {
            // 忽略解析失败的数据行
        }
    }
}